#!/usr/bin/env python
# -*- coding: utf-8 -*-

from jujuz.protocol import Protocol,ClientFactory
from jujuz.reactor import Reactor

class   EchoClient(Protocol) :
    def OnConnectionMade(self) :
        self.transport.write('Hello,World!')
        # OnConnectionMade()

    def OnDataReceived(self, data) :
        print 'SERVER said:',data
        self.transport.loseConnection()
        # OnDataReceived()

    def OnConnectionLost(self, reason) :
        print 'connection lost'
        # OnConnectionLost

    # class EchoClient

class   EchoFactory(ClientFactory) :
    protocol = EchoClient

    def OnClientConnectionFailed(self, connector, reason) :
        print 'connection failed -- byebye.'
        self.reactor.stop()

    def OnClientConnectionLost(self, connector, reason) :
        print 'connection lost -- byebye.'
        self.reactor.stop()

    # class EchoFactory

factory = EchoFactory()
reactor = Reactor()
reactor.connectTCP('localhost', 4344, factory)
reactor.run()
